import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
// import data from "./utils/dataUtil.js";
import VueSocketio from "vue-socket.io";
import SocketIO from "socket.io-client";
import axios from "axios";

// vant
// import { DatetimePicker } from "vant";
// Vue.use(DatetimePicker);

// MintUI
import MintUI from "mint-ui";
import "mint-ui/lib/style.css";
import { Picker } from "mint-ui";
import { DatetimePicker } from "mint-ui";
import { Actionsheet } from "mint-ui";
import { Popup } from "mint-ui";

// 图片
import VueUploadImgs from "vue-upload-imgs";
Vue.use(VueUploadImgs);

Vue.component(Popup.name, Popup);
Vue.component(Actionsheet.name, Actionsheet);
Vue.use(MintUI);
Vue.component(DatetimePicker.name, DatetimePicker);
Vue.component(Picker.name, Picker);

axios.defaults.baseURL = "http://localhost:8848";
axios.defaults.headers.post["Content-Type"] =
  "application/x-www-form-urlencoded";
Vue.prototype.$http = axios;

// socket 连接参数
const socketOptions = {
  autoConnect: true // 自动连接  这里为我项目需求  需要在指定情况下才连接socket
};
Vue.use(
  new VueSocketio(
    { connection: SocketIO("ws://localhost:8848/", socketOptions) },
    store
  )
);

Vue.config.productionTip = false;
Vue.filter("dateFormat", function(originVal) {
  const dt = new Date(originVal);
  // const y = dt.getFullYear();
  const m = (dt.getMonth() + 1 + "").padStart(2, "0"); //padStart 用于头部补全长度
  const d = (dt.getDate() + "").padStart(2, "0");

  const hh = (dt.getHours() + "").padStart(2, "0");
  const mm = (dt.getMinutes() + "").padStart(2, "0");
  // const ss = (dt.getSeconds() + "").padStart(2, "0");

  return `${m}-${d} ${hh}:${mm}`;
});

Vue.filter("dateFor", function(originVal) {
  const dt = new Date(originVal);
  const y = dt.getFullYear();
  const m = (dt.getMonth() + 1 + "").padStart(2, "0"); //padStart 用于头部补全长度
  const d = (dt.getDate() + "").padStart(2, "0");

  return `${y}-${m}-${d}`;
});

new Vue({
  router,
  store,
  sockets: {
    connecting() {
      console.log("正在连接");
    },
    disconnect() {
      console.log("Socket 断开");
    },
    connect_failed() {
      cosnole.log("连接失败");
    },
    connect() {
      console.log("socket connected");
    }
  },
  render: h => h(App)
}).$mount("#app");
